package com.cap.dreamcircle.Model.Impl;

import com.cap.dreamcircle.Api.DreamService;
import com.cap.dreamcircle.Model.Bean.AdCommentBean;
import com.cap.dreamcircle.Model.Bean.AdsArticleBean;
import com.cap.dreamcircle.Model.Bean.ArticalDeteial;
import com.cap.dreamcircle.Model.Bean.BaseBean;
import com.cap.dreamcircle.Model.Bean.DreamCircleFriendsBean;
import com.cap.dreamcircle.Model.Bean.DreamCircleUserRecordsBean;
import com.cap.dreamcircle.Model.Bean.DreamDetailBean;
import com.cap.dreamcircle.Model.Bean.DreamLabelBean;
import com.cap.dreamcircle.Model.Bean.DreamLabelDetailBean;
import com.cap.dreamcircle.Model.Bean.DreamRecordsMonthlyBean;
import com.cap.dreamcircle.Model.Bean.SelfSimpleDreamRecordsBean;
import com.cap.dreamcircle.Model.Bean.SolveDreamBean;
import com.cap.dreamcircle.Model.IDreamModel;
import com.cap.dreamcircle.Utils.ServiceFactory;
import com.cap.dreamcircle.Utils.TransformUtils;

import java.util.HashMap;
import java.util.Map;

import okhttp3.RequestBody;
import rx.Observable;

/**
 * Created by liucxu on 2017/8/10.
 */

public class DreamModelImpl implements IDreamModel {
    @Override
    public Observable<BaseBean> RecordDream(Map<String, RequestBody> params) {
        return ServiceFactory.GetInstance().createService(DreamService.class).RecordDream(params);
    }

    @Override
    public Observable<SelfSimpleDreamRecordsBean> SelfSimpleDreamRecords(int page_index) {
        HashMap<String,String> params=new HashMap<>();
        params.put("task","queryMyDreamList");
        params.put("pageNum",""+page_index);
        return ServiceFactory.GetInstance().createService(DreamService.class).SelfSimpleDreamRecords(params);
    }

    @Override
    public Observable<DreamDetailBean> DreamRecordDetail(String dreamId) {
        HashMap<String,String> params=new HashMap<>();
        params.put("task","queryDreamRecordById");
        params.put("dreamId",dreamId);
        return ServiceFactory.GetInstance().createService(DreamService.class).DreamRecordDetail(params);
    }

    @Override
    public Observable<BaseBean> PostDreamComment(String comments,String dreamId,String toUserId,String toCommentId,boolean isAnonymous) {
        HashMap<String,String> params=new HashMap<>();
        params.put("task","postDreamRecordComment");
        params.put("dreamId",dreamId);
        params.put("commentContent",comments);
        params.put("toUserId",toUserId);
        params.put("toCommentId",toCommentId);
        if(isAnonymous){
            params.put("showName","n");
        }
        else{
            params.put("showName","y");
        }
        return ServiceFactory.GetInstance().createService(DreamService.class).PostDreamComment(params);
    }

    @Override
    public Observable<DreamLabelDetailBean> RequestDreamLabelDetail(String tagId, String tagName) {
        HashMap<String,String> params=new HashMap<>();
        params.put("task","queryDreamResultByTag");
        params.put("tagId",tagId);
        params.put("tagName",tagName);
        return ServiceFactory.GetInstance().createService(DreamService.class).RequestDreamLabelDetail(params);
    }

    @Override
    public Observable<DreamRecordsMonthlyBean> RequestDreamRecordsMonthly(String year, String month) {
        HashMap<String,String> params=new HashMap<>();
        params.put("task","queryDreamRecordByMonth");
        params.put("year",year);
        params.put("month",month);
        return ServiceFactory.GetInstance().createService(DreamService.class).RequestDreamRecordsMonthly(params);
    }

    @Override
    public Observable<DreamCircleFriendsBean> RequestDreamCircleRecords(int page_index) {
        HashMap<String,String> params=new HashMap<>();
        params.put("task","queryDreamRecordCircle");
        params.put("pageNum",page_index+"");
        return ServiceFactory.GetInstance().createService(DreamService.class).RequestDreamCircleRecords(params);
    }

    @Override
    public Observable<BaseBean> DeleteDreamCircleById(String dreamId) {
        HashMap<String,String> params=new HashMap<>();
        params.put("task","deleteDreamRecord");
        params.put("dreamId",dreamId+"");
        return ServiceFactory.GetInstance().createService(DreamService.class).DeleteDreamCircleById(params);
    }

    @Override
    public Observable<BaseBean> LikeDreamCircleRecord(String dreamId) {
        HashMap<String,String> params=new HashMap<>();
        params.put("task","likeDreamRecord");
        params.put("dreamId",dreamId);
        return ServiceFactory.GetInstance().createService(DreamService.class).LikeDreamCircleRecord(params);
    }

    @Override
    public Observable<DreamCircleUserRecordsBean> RequestUserDreamRecord(String userId, int pageNum) {
        HashMap<String,String> params=new HashMap<>();
        params.put("task","queryDreamRecordByUser");
        params.put("toUserId",userId);
        params.put("pageNum",pageNum+"");
        return ServiceFactory.GetInstance().createService(DreamService.class).RequestUserDreamRecord(params);
    }

    @Override
    public Observable<DreamCircleUserRecordsBean> RequestDreamRecordByDay(String day) {
        HashMap<String,String> params=new HashMap<>();
        params.put("task","queryDreamRecordByDay");
        params.put("day",day);
        return ServiceFactory.GetInstance().createService(DreamService.class).RequestDreamRecordByDay(params);
    }

    @Override
    public Observable<SolveDreamBean> RequestSolveDreamRecordTalk(String dreamId, String pre_anchor,String last_anchor) {
        HashMap<String,String> params=new HashMap<>();
        params.put("task","queryDreamRecordTalk");
        params.put("dreamId",dreamId);
        params.put("lastId",last_anchor);
        params.put("firstId",pre_anchor);
        return ServiceFactory.GetInstance().createService(DreamService.class).RequestSolveDreamRecordTalk(params);
    }

    @Override
    public Observable<BaseBean> PostDreamRecordTalk(String dreamId, String content) {
        HashMap<String,String> params=new HashMap<>();
        params.put("task","postDreamRecordTalk");
        params.put("dreamId",dreamId);
        params.put("content",content);
        return ServiceFactory.GetInstance().createService(DreamService.class).PostDreamRecordTalk(params).compose(TransformUtils.<BaseBean>defaultSchedulers());
    }

    @Override
    public Observable<DreamLabelBean> QueryTagsByKeyWords(String keywords) {
        HashMap<String,String> params=new HashMap<>();
        params.put("task","queryTagsByKeyWords");
        params.put("keyWords",keywords);
        return ServiceFactory.GetInstance().createService(DreamService.class).QueryTagsByKeyWords(params).compose(TransformUtils.<DreamLabelBean>defaultSchedulers());
    }

    @Override
    public Observable<DreamLabelBean> RequestDreamLabel(String pageNum) {
        HashMap<String,String> params=new HashMap<>();
        params.put("task","queryRandomTags");
        params.put("pageNum",pageNum);
        return ServiceFactory.GetInstance().createService(DreamService.class).RequestDreamLabel(params);
    }

    @Override
    public Observable<AdsArticleBean> RequestMainPageAds() {
        HashMap<String,String> params=new HashMap<>();
        params.put("task","queryAd");
        return ServiceFactory.GetInstance().createService(DreamService.class).RequestMainPageAds(params).compose(TransformUtils.<AdsArticleBean>defaultSchedulers());
    }

    @Override
    public Observable<BaseBean> ReportDreamRecord(String dreamId) {
        HashMap<String,String> params=new HashMap<>();
        params.put("task","jubao");
        params.put("dreamId",dreamId);
        return ServiceFactory.GetInstance().createService(DreamService.class).ReportDreamRecord(params).compose(TransformUtils.<BaseBean>defaultSchedulers());
    }

    @Override
    public Observable<AdCommentBean> QueryAdComments(String AdId) {
        HashMap<String,String> params=new HashMap<>();
        params.put("task","queryAdComment");
        params.put("dreamAdId",AdId);
        return ServiceFactory.GetInstance().createService(DreamService.class).QueryAdComments(params).compose(TransformUtils.<AdCommentBean>defaultSchedulers());
    }

    @Override
    public Observable<BaseBean> PostAdComment(String AdId, String comment,String toCommentId,String toUserId) {
        HashMap<String,String> params=new HashMap<>();
        params.put("task","postAdComment");
        params.put("dreamAdId",AdId);
        params.put("commentContent",comment);
        params.put("toCommentId",toCommentId);
        params.put("toUserId",toUserId);
        params.put("showName","y");
        return ServiceFactory.GetInstance().createService(DreamService.class).PostAdComment(params).compose(TransformUtils.<BaseBean>defaultSchedulers());
    }

    @Override
    public Observable<BaseBean> LikeArtical(String dreamAdId) {
        HashMap<String,String> params=new HashMap<>();
        params.put("task","likeAd");
        params.put("dreamAdId",dreamAdId);
        return ServiceFactory.GetInstance().createService(DreamService.class).LikeArtical(params).compose(TransformUtils.<BaseBean>defaultSchedulers());
    }

    @Override
    public Observable<BaseBean> HasReadArtical(String articalId) {
        HashMap<String,String> params=new HashMap<>();
        params.put("task","readAd");
        params.put("adId",articalId);
        return ServiceFactory.GetInstance().createService(DreamService.class).HasReadArtical(params).compose(TransformUtils.<BaseBean>defaultSchedulers());
    }

    @Override
    public Observable<ArticalDeteial> QuertyArticalDetail(String adId) {
        HashMap<String,String> params=new HashMap<>();
        params.put("task","queryAdDetail");
        params.put("adId",adId);
        return ServiceFactory.GetInstance().createService(DreamService.class).QuertyArticalDetail(params).compose(TransformUtils.<ArticalDeteial>defaultSchedulers());
    }
}